//
//  TTDiamondDetailInfoViewCell.m
//  TaoTuo
//
//  Created by 周晨晔 on 2019/9/18.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTDiamondDetailInfoViewCell.h"

@interface TTDiamondDetailInfoViewCell ()

@property (nonatomic, strong) UILabel *leftTitleLabel;
@property (nonatomic, strong) UILabel *leftContentLabel;

@property (nonatomic, strong) UILabel *rightTitleLabel;
@property (nonatomic, strong) UILabel *rightContenLabel;
@property (nonatomic, strong) UIButton *btn;
//@property (nonatomic, strong) UIButton *fuzhiBtn;   // 复制

@end

@implementation TTDiamondDetailInfoViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}


- (void)setDic:(NSDictionary *)dic
{
    _dic = dic;
    
    self.leftTitleLabel.text = [NSString stringWithFormat:@"%@: ", dic[@"leftTitle"]];
    self.leftContentLabel.text = dic[@"leftContent"];
    self.rightContenLabel.text = dic[@"rightContent"];
    
    
    NSString *rightTitleStr = [dic[@"rightTitle"] length] > 0 ? [NSString stringWithFormat:@"%@: ", dic[@"rightTitle"]] : @"";
    self.rightTitleLabel.text = rightTitleStr;

    NSString *btnTitle = dic[@"leftButtonTitle"];
    if (btnTitle.length > 0) {
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:btnTitle attributes:@{NSUnderlineStyleAttributeName : @1, NSUnderlineColorAttributeName : kMainColor, NSForegroundColorAttributeName : kMainColor}];
        [self.btn setAttributedTitle:attr forState:UIControlStateNormal];
    }
    self.btn.hidden = btnTitle.length == 0;

    
    
}

// 点击按钮
- (void)clickBtn
{
    if ([self.btn.titleLabel.text containsString:@"证书预览"]) {
        if ([self.delegate respondsToSelector:@selector(lookVervifyWithDetailInfoViewCell:)]) {
            [self.delegate lookVervifyWithDetailInfoViewCell:self];
        }
        
    } else {
        // 用自带浏览器打开
        if ([self.delegate respondsToSelector:@selector(queryWebsiteWithDetailInfoViewCell:)]) {
            [self.delegate queryWebsiteWithDetailInfoViewCell:self];
        }
    }
}

//// 复制按钮
//- (void)clickFuzhiBtn
//{
//    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
//    pasteboard.string = self.rightContenLabel.text;
//    [[UIApplication sharedApplication].keyWindow makeToast:@"已复制到剪贴板" duration:1 position:CSToastPositionCenter];
//}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.leftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).mas_equalTo(10);
        make.top.height.equalTo(self.contentView);
    }];
    
    
    MASViewAttribute *right = self.contentView.mas_centerX;
    CGFloat offset = 0;
    if (self.rightTitleLabel.text.length == 0) {
        right = self.contentView.mas_right;
        offset = -10;
    }
    [self.leftContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftTitleLabel.mas_right);
        make.top.height.equalTo(self.leftTitleLabel);
    }];
    
    [self.rightTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_centerX);
        make.top.height.equalTo(self.contentView);
    }];
    
    [self.rightContenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.rightTitleLabel.mas_right);
        make.right.lessThanOrEqualTo(self.contentView).mas_offset(-10 * kScale);
        make.top.height.equalTo(self.leftTitleLabel);
    }];
    
    [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftContentLabel.mas_right).mas_offset(3);
        make.height.top.equalTo(self.contentView);
    }];
    
//    [self.fuzhiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
////        make.left.equalTo(self.btn.mas_right).mas_offset(5 * kScale);
//        make.right.equalTo(self.contentView).mas_offset(-5);
//        make.height.top.equalTo(self.contentView);
//    }];
    
}

- (UILabel *)leftTitleLabel
{
    if (!_leftTitleLabel) {
        _leftTitleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:14];
        [self.contentView addSubview:_leftTitleLabel];
    }
    return _leftTitleLabel;
}

- (UILabel *)leftContentLabel
{
    if (!_leftContentLabel) {
        _leftContentLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:14];
        [self.contentView addSubview:_leftContentLabel];
    }
    return _leftContentLabel;
}


- (UILabel *)rightTitleLabel
{
    if (!_rightTitleLabel) {
        _rightTitleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:14];
        [self.contentView addSubview:_rightTitleLabel];
    }
    return _rightTitleLabel;
}

- (UILabel *)rightContenLabel
{
    if (!_rightContenLabel) {
        _rightContenLabel = [UILabel labelWithTitle:@"" color:UIColorHex(666666) fontSize:14];
        [self.contentView addSubview:_rightContenLabel];
    }
    return _rightContenLabel;
}

- (UIButton *)btn
{
    if (!_btn) {
        _btn = [UIButton createButtonWithTitle:@"" titleColor:kMainColor titleFont:[UIFont systemFontOfSize:14] backgroundColor:[UIColor whiteColor] target:self action:@selector(clickBtn)];
        [self.contentView addSubview:_btn];
    }
    return _btn;
}

//- (UIButton *)fuzhiBtn
//{
//    if (!_fuzhiBtn) {
//        _fuzhiBtn = [UIButton createButtonWithTitle:@"复制" titleColor:kMainColor titleFont:[UIFont systemFontOfSize:12] backgroundColor:[UIColor whiteColor] target:self action:@selector(clickFuzhiBtn)];
//        [self.contentView addSubview:_fuzhiBtn];
//    }
//    return _fuzhiBtn;
//}

@end
